<?php
namespace wechat;
use EasyWeChat\Factory;
class Wechat {
    /**
     * @var object 对象实例
     * https://easywechat.com/5.x/official-account/
     */
    protected static $instance;
    protected $rules = [];

    /**
     * 当前请求实例
     * @var Request
     */
    protected $app;
    //默认配置
    protected $config = [
        'app_id'           => '', //公众号appId
        'secret'         => '', //公众号secret。
        'response_type' => 'array',
    ];

    public function __construct()
    {
        if ($wechat = Config::get('wechat')) {
            $this->config = array_merge($this->config, $wechat);
        }
        
    }
    /**
     * 初始化
     * @access public
     * @param array $options 参数
     * @return Wechat
     */
    public static function instance($options = [])
    {
        if (is_null(self::$instance)) {
            self::$instance = new static($options);
        }

        return self::$instance;
    }

    public function validate(){
        $app = Factory::officialAccount($this->config);
        $response = $app->server->serve();
        // 将响应输出
        $response->send(); exit;
    }
}